﻿# 源文件收集
file(GLOB_RECURSE LIB_SOURCES src/*.cpp)
file(GLOB_RECURSE LIB_HEADERS include/*.h)

# 创建库目标
add_library(libunits ${LIB_SOURCES})
add_library(libunits::libunits ALIAS libunits)

# 设置正确输出名
set_target_properties(libunits PROPERTIES
    OUTPUT_NAME "units"
    PREFIX ""
    ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
)

# 包含目录
target_include_directories(libunits PUBLIC
    $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
    $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
    PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src
)

# 链接依赖
target_link_libraries(libunits PUBLIC
    units::units
    libconfig++
)

# 静态库定义
if(NOT BUILD_SHARED_LIBS)
    target_compile_definitions(libunits PRIVATE
        UNITS_STATIC_DEFINE
        LIBCONFIG_STATIC
        LIBCONFIGXX_STATIC
    )
endif()

# 安装规则
install(TARGETS libunits
    EXPORT libunitsTargets
    ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
    INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)

# 安装头文件到标准位置
install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})

# 安装头文件到 build/include
install(DIRECTORY include/ DESTINATION ${CMAKE_BINARY_DIR}/include)

# 导出配置 - 移除导出集依赖
# 改为在libunitsConfig.cmake.in中手动处理
